package edu.nf.ch08.mapper;

import edu.nf.ch08.entity.User;
import org.apache.ibatis.annotations.*;

/**
 * @author wangl
 * @date 2025/4/25
 */
public interface UserMapper {

    @Insert("insert into stu_info(s_name, s_age) values(#{name}, #{age})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(User user);

    @Update("update stu_info set s_name = #{name} where s_id = #{id}")
    void update(User user);

    @Delete("delete from stu_info where s_id = #{id}")
    void delete(int id);

    @Select("select s_id as id, s_name as name, s_age as age from stu_info where s_id =#{id}")
    //@ResultType(User.class)
    //使用@ResultMap时，value的值是namespace + resultMap的id
    @ResultMap("edu.nf.ch08.mapper.UserMapper.userMap")
    User getUserById(int id);
}